<template>
  <div>
<!--    <el-switch-->
<!--        v-model="value"-->
<!--        active-color="#13ce66"-->
<!--        inactive-color="#ff4949" style="margin: 0px 0px 10px 0px" @click="turnoff">-->
<!--    </el-switch>-->
    <i></i>

    <el-table :data="tableData" border stripe :header-cell-class-name="headerBg"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="fields.pi" label="小车编号" width="200"></el-table-column>
      <el-table-column prop="fields.data" label="湿度" width="200"></el-table-column>
      <el-table-column prop="fields.time" label="检测时间" width="200"></el-table-column>



    </el-table>
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[2, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>


<script>

export default {
  name: 'Data',
  data() {
    return {
      value: true,
      car1:'192.168.43.66',//小车1ip，根据实际情况修改
      car2:'192.168.43.193',//小车2ip
      car3:'192.168.43.194',//小车3ip
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 10,
      dialogFormVisible: false,
      form: {},
      multipleSelection: [],
      headerBg: 'headerBg'
    }
  },
  created() {
    this.load()
    this.click()
  },

  methods: {
    click () {
      let  timer = setInterval(() => {
        this.fun(timer)
      }, 4000)
    },
    fun (timer) {
      setTimeout(()=>{
        // 这里ajax 请求的代码片段和判断是否停止定时器
        // console.log(timer)
        this.load()
        // 如需要停止定时器，只需加入以下：
        // clearInterval(timer)
      }, 0)
    },

    load(){
      this.request.get("/api/car_sensor", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          // car: this.radio,
        }
      }).then(res => {
        // res = JSON.parse(res.bodyText);
        console.log(res)
        this.tableData = res.list

        console.log('table',this.tableData)
        this.total = res.total
      })

    },

    turnoff(){
      this.tableData = []
      console.log(this.tableData)
    },

    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val
    },


    handleSizeChange(pageSize) {
      console.log(pageSize)
      this.pageSize = pageSize
      this.load()
    },

    handleCurrentChange(pageNum) {
      console.log(pageNum)
      this.pageNum = pageNum
      this.load()
    }
  }
}
</script>